(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
})(jQuery);
(function () {
    if (localStorage.getItem("rememberMe") === "0") {
        token = sessionStorage.getItem("token")
        userName = sessionStorage.getItem("userName")
        userIdP =  sessionStorage.getItem("userIdP")
    } else {
        token = localStorage.getItem("token")
        userName = localStorage.getItem("userName")
        userIdP = localStorage.getItem("userIdP")
    }
    getVersion();
})();

function getVersion() {
    $.ajax({
        url: "/user/queryVersion/"+userIdP,
        type: "GET",
        success: function (data) {
            version = data.data;
        }
    })

}

//请确认
/*$("#confirmAdd").click(function () {
    if ($(this)[0].checked){
        $("#addSubmit").attr("disabled",false);
    }else {
        $("#addSubmit").attr("disabled",true);
    }
})*/


//添加
$("#addSubmit").click(function () {
    if (3 > 2) {
        var $file1 = $("#fileBody").val();//用户文件内容(文件)
        // 判断文件是否为空
        if ($file1 === "") {
            alert("请选择上传的目标文件! ")
            return false;
        }
        //判断文件类型,我这里根据业务需求判断的是Excel文件
        var fileName1 = $file1.substring($file1.lastIndexOf(".") + 1).toLowerCase();
        // if(fileName1 !== "jpg" && fileName1 !=="jpeg" && fileName1 !=="ico" && fileName1 !=="png"){
        //     alert("请选择图片文件!");
        //     return false;
        // }
        //判断文件大小
        var size1 = $("#fileBody")[0].files[0].size;
        if (size1>3072576000) {
            alert("上传文件不能大于3G!");
            return false;
        }

        var type = "file";
        var formData = new FormData();//这里需要实例化一个FormData来进行文件上传
        formData.append(type,$("#fileBody")[0].files[0]);
        //多文件上传在这里继续append
        //eg :
        //formData.append(type,$("#fileName1")[0].files[0]);


        $.ajax({
            url: "/file/upFile",
            type: "POST",
            headers: {'Authorization': token,'userId':userIdP},
            data : formData,
            processData : false,
            contentType : false,
            success : function(data){
                if (data.msg===null) {
                    alert("文件提交失败!");
                }else{
                    alert("文件上传成功!");
                }}, error() {
                if(token != null && token!== ""){
                    alert("添加文件有误，请重新输入！")
                }else {
                    location.href = encodeURI("../login.html")
                }
            }
        })
    } else {
        alert("权限不足")
    }
})


$("#back").click(function () {
    history.back(-1);
    //location.href = encodeURI("patients.html")
})



